package ModelLayer;
import java.util.*;


public class DVD
{
    // instance variables
    private long id;
    private String title;
    private String artist;
    private String publicationDate;
    public ArrayList<Copy> copy;
    /**
     * Constructor
     */
    public DVD(long _id, String _title, String _artist, String _publicationDate)
    {
        id= _id;
        title=_title;
        artist=_artist;
        publicationDate=_publicationDate;
        copy = new ArrayList<Copy>();
        // initialise instance variables

    }

    /**
     *Accessors 
     */

    public long getID()
    {
        return id;
    }

    public String getTitle()
    { 
        return title;
    }

    public String getArtist()
    { 
        return artist;
    }

    public String getPublicationDate()
    {
        return publicationDate;
    }

    /**
     * Mutators
     */
    public void setID(long _value)
    { 
        id = _value;
    }

    public void setTitle(String _value)
    {
        title=_value;
    }

    public void setArtist(String _value)
    {
        artist=_value;
    }

    public void setPublicationDate(String _value)
    {
        publicationDate=_value;
    }

    /**
     * Methods for Copy arrayList of the DVDs
     * Add a new copy of the DVD,return the whole list of the copies, find a copy after its Serial Number,
     * check if the DVD has a copy using the findCopy method, delete a Copy, and print all copies of a dvd.
     */

    public void newCopy(Copy _newCopy)
    { 
        copy.add(_newCopy);
    }

    public ArrayList<Copy> getCopyList()
    {
        return copy;
    }

    public String PrintAllCopies()
    {
        String str="";
        for(Copy cpy : copy)
            str += cpy.getSerialNumber()+ " ";
        return str;
    }

    public Copy findCopy(String _serialNumber)
    {   
        Copy tempCopy = null;
        int i=0;
        boolean found = false;
        while (i<copy.size() &&!found)
        {   Copy cpy = copy.get(i);
            if(cpy.getSerialNumber().equals(_serialNumber))
            {   tempCopy= cpy;
                found = true;
            }
            else
                i++;
        }
        return tempCopy;
    }

    public boolean hasCopy(String _SerialNumber)
    {
        boolean found = false;
        for(Copy cpy : copy)
        {
            if(cpy.getSerialNumber().equals(_SerialNumber))
            {
                found = true;
            }
        }
        return found;
    }

    public void deleteCopy(String _SerialNumber)
    {   Copy delCopy = findCopy( _SerialNumber);
        if(delCopy !=null)
        {copy.remove(delCopy);}
    }

}
